package com.jianbing.zuixia.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.jianbing.common.annotation.Log;
import com.jianbing.common.core.controller.BaseController;
import com.jianbing.common.core.domain.AjaxResult;
import com.jianbing.common.enums.BusinessType;
import com.jianbing.zuixia.domain.ZuixiaQuestionBank;
import com.jianbing.zuixia.service.IZuixiaQuestionBankService;
import com.jianbing.common.utils.poi.ExcelUtil;
import com.jianbing.common.core.page.TableDataInfo;

/**
 * 题库，存储所有题目的信息Controller
 * 
 * @author windbless
 * @date 2024-06-18
 */
@RestController
@RequestMapping("/zuixia/bank")
public class ZuixiaQuestionBankController extends BaseController
{
    @Autowired
    private IZuixiaQuestionBankService zuixiaQuestionBankService;

    /**
     * 查询题库，存储所有题目的信息列表
     */
//    @PreAuthorize("@ss.hasPermi('zuixia:bank:list')")
    @GetMapping("/list")
    public TableDataInfo list(ZuixiaQuestionBank zuixiaQuestionBank)
    {
        startPage();
        List<ZuixiaQuestionBank> list = zuixiaQuestionBankService.selectZuixiaQuestionBankList(zuixiaQuestionBank);
        return getDataTable(list);
    }

    /**
     * 导出题库，存储所有题目的信息列表
     */
//    @PreAuthorize("@ss.hasPermi('zuixia:bank:export')")
    @Log(title = "题库，存储所有题目的信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ZuixiaQuestionBank zuixiaQuestionBank)
    {
        List<ZuixiaQuestionBank> list = zuixiaQuestionBankService.selectZuixiaQuestionBankList(zuixiaQuestionBank);
        ExcelUtil<ZuixiaQuestionBank> util = new ExcelUtil<ZuixiaQuestionBank>(ZuixiaQuestionBank.class);
        util.exportExcel(response, list, "题库，存储所有题目的信息数据");
    }

    /**
     * 获取题库，存储所有题目的信息详细信息
     */
//    @PreAuthorize("@ss.hasPermi('zuixia:bank:query')")
    @GetMapping(value = "/{questionId}")
    public AjaxResult getInfo(@PathVariable("questionId") Long questionId)
    {
        return success(zuixiaQuestionBankService.selectZuixiaQuestionBankByQuestionId(questionId));
    }

    /**
     * 新增题库，存储所有题目的信息
     */
//    @PreAuthorize("@ss.hasPermi('zuixia:bank:add')")
    @Log(title = "题库，存储所有题目的信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ZuixiaQuestionBank zuixiaQuestionBank)
    {
        return toAjax(zuixiaQuestionBankService.insertZuixiaQuestionBank(zuixiaQuestionBank));
    }

    /**
     * 修改题库，存储所有题目的信息
     */
//    @PreAuthorize("@ss.hasPermi('zuixia:bank:edit')")
    @Log(title = "题库，存储所有题目的信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ZuixiaQuestionBank zuixiaQuestionBank)
    {
        return toAjax(zuixiaQuestionBankService.updateZuixiaQuestionBank(zuixiaQuestionBank));
    }

    /**
     * 删除题库，存储所有题目的信息
     */
//    @PreAuthorize("@ss.hasPermi('zuixia:bank:remove')")
    @Log(title = "题库，存储所有题目的信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{questionIds}")
    public AjaxResult remove(@PathVariable Long[] questionIds)
    {
        return toAjax(zuixiaQuestionBankService.deleteZuixiaQuestionBankByQuestionIds(questionIds));
    }
}
